package com.literaryfamily.literaryfamily.enumPackage;

import com.literaryfamily.literaryfamily.exceptions.OperationException;

/**
 * 验证短信用途
 */
public enum CodeType {
	LOGIN(0, "登录"),
	REGISTER(1, "注册"),
	UPDATE_PASSWORD(2, "修改敏感信息"),
	LOST_PASSWORD(3, "忘记密码"),
	;
	/**
	 * 用途代码
	 */
	private final int code;

	public String getTypeName() {
		return typeName;
	}

	public int getCode() {
		return code;
	}

	/**
	 * 用途名称
	 */
	private final String typeName;

	CodeType(int code, String typeName) {
		this.code = code;
		this.typeName = typeName;
	}

	public static CodeType getCode(int code) {
		return switch (code) {
			case 0 -> LOGIN;
			case 1 -> REGISTER;
			case 2 -> UPDATE_PASSWORD;
			case 3 -> LOST_PASSWORD;
			default -> throw new OperationException("不存在的验证码类型");
		};
	}
}